package com.site.wisdom_construction.controller.scheduleModule;

import com.site.wisdom_construction.responseEntity.JsonResult;
import com.site.wisdom_construction.responseEntity.OneDataResult;
import com.site.wisdom_construction.service.scheduleModule.ProgressPlanService;
import com.site.wisdom_construction.util.tree.ProgressPlanTreeUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2022/6/21
 * @Description
 */
@Api(tags = "编制计划接口")
@RestController
@RequestMapping("ProgressPlan")
@CrossOrigin
public class ProgressPlanController {
    @Autowired
    private ProgressPlanService progressPlanService;

    @ApiOperation(value = "增加编制计划", notes = "测试数据:")
    @PostMapping("/insertProgressPlan")
    public JsonResult insertProgressPlan(@RequestBody Map map) {
        JsonResult jsonResult = new JsonResult();

        int a = progressPlanService.insertProgressPlan(map);
        if (a == 1) {
            jsonResult.setCode(200);
            jsonResult.setMessage("成功增加编制计划!");
        } else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("增加编制计划失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "删除编制计划", notes = "测试数据:")
    @PostMapping("/deleteProgressPlan")
    public JsonResult deleteProgressPlan(@RequestBody Map map) {
        JsonResult jsonResult = new JsonResult();

        int a = progressPlanService.deleteProgressPlan(map);
        if (a == 1) {
            jsonResult.setCode(200);
            jsonResult.setMessage("成功删除编制计划!");
        } else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("删除编制计划失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "树形图", notes = "测试数据:")
    @PostMapping("/findProgressPlanByProjectId")
    public OneDataResult findProgressPlanByProjectId(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        ProgressPlanTreeUtil progressPlanTreeUtil = new ProgressPlanTreeUtil();
        oneDataResult.setData(progressPlanTreeUtil.menuList(progressPlanService.findProgressPlanByProjectId(map)));
        return oneDataResult;
    }
}
